// 主页
<template>
  <div class="businessdata">
    <div class="homeData-left">
      <ul>
        <li :class="{'barLi':true,'barSelectLi':isBarSelectLi == index,'barNoSelectLi':isBarNoSelectLi == index}" v-for="(item,index) in barLists" :key="index" @click="barListsClick(index)" @mouseover="barListsMouse(index)">
          {{item.name}}
        </li>
      </ul>
    </div>
    <div class="homeData-right">
      <router-view keep-alive></router-view>
    </div>
  </div>
</template>
<script>
import { mapActions } from "vuex";
export default {
  data() {
    return {
      isBarSelectLi: 0, // 选中侧栏
      isBarNoSelectLi: -1, // 未选中侧栏
      barLists: [
        { name: "成员使用统计", path: "statistics" }
        // { name: "管理员操作记录", path: "adminlist" }
      ] //侧栏列表
    };
  },
  filters: {},
  created: function() {
    var self = this;
    var accessToken = sessionStorage.getItem("accessToken");
    if (accessToken) {
      this.fetchPathFun();
    } else {
      this.$router.push({
        path: "/login"
      });
    }
  },
  watch: {},
  methods: {
    // 应用列表
    listFun() {
      var self = this;
      self
        .getRpcOrgAppWorkIndex({
          orgId: sessionStorage.getItem("ORGID")
        })
        .then(data => {
          if (data.statusCode == 200) {
            if (data.data) {
              if (data.data.indexVos) {
                self.lists = [];
                data.data.indexVos.forEach(function(elel, ind1) {
                  self.appIdLists.forEach(function(eler, indr) {
                    if (elel.appKey == eler) {
                      if (elel.name == "日志") {
                        self.lists.push({
                          name: "日志",
                          path: "loglist",
                          logo: elel.logo
                        });
                      } else if (elel.name == "审批") {
                        self.lists.push({
                          name: "审批",
                          path: "examine",
                          logo: elel.logo
                        });
                      } else if (elel.name == "签到") {
                        self.lists.push({
                          name: "签到",
                          path: "sign",
                          logo: elel.logo
                        });
                      } else if (elel.name == "资讯") {
                        self.lists.push({
                          name: "资讯",
                          path: "information",
                          logo: elel.logo
                        });
                      } else if (elel.name == "公告") {
                        self.lists.push({
                          name: "公告",
                          path: "notice",
                          logo: elel.logo
                        });
                      } else {
                        self.lists.push({
                          name: "工作台",
                          path: "network",
                          logo: elel.logo
                        });
                      }
                    }
                  });
                });
              }
            }
          } else if (data.statusCode == "200003") {
            self.$message({
              type: "info",
              message: data.statusMessage
            });
            this.$router.push({
              path: "/login"
            });
          } else {
            self.$message({
              type: "info",
              message: data.statusMessage
            });
          }
        })
        .catch(msg => {
          self.$message({
            type: "info",
            message: "服务器异常"
          });
        });
    },
    // 企业主页
    orgHome() {
      var self = this;
      var obj = {
        companyId: sessionStorage.getItem("ORGID"),
        passportId: sessionStorage.getItem("passportPwdId")
      };
      if (sessionStorage.getItem("ORGID")) {
        self
          .getapiorghome({
            companyId: sessionStorage.getItem("ORGID"),
            passportId: sessionStorage.getItem("passportPwdId")
          })
          .then(data => {
            if (data.statusCode == 200) {
              if (data.data) {
                self.OrgOBj = data.data;
                var standardTime = new Date();
                var y, m, d, h, f;
                y = standardTime.getFullYear();
                m = standardTime.getMonth() + 1;
                m = m > 9 ? m : "0" + m;
                d = standardTime.getDate();
                d = d - 1;
                d = d > 9 ? d : "0" + d;
                var time = y + "-" + m + "-" + d;
                for (var key in data.data.memberRecord) {
                  if (time == key) {
                    if (data.data.memberRecord[key]) {
                      self.useCount = data.data.memberRecord[key].length;
                    }
                  }
                }
                self.orgLogo = data.data.orgLogo;
                if (data.data.subData) {
                  sessionStorage.setItem(
                    "memberId",
                    data.data.subData.memberId
                  );
                  sessionStorage.setItem(
                    "adminType",
                    data.data.subData.adminType
                  );
                  if (data.data.subData.appIds) {
                    self.appIdLists = data.data.subData.appIds;
                  }
                }

                if (data.data.member) {
                  sessionStorage.setItem("mobile", data.data.member.mobile);
                  sessionStorage.setItem(
                    "memberName",
                    data.data.member.memberName
                  );
                }
                self.listFun();
              } else {
                self.OrgOBj = {};
              }
            } else if (data.statusCode == "200003") {
              self.$message({
                type: "info",
                message: data.statusMessage
              });
              this.$router.push({
                path: "/login"
              });
            } else {
              self.$message({
                type: "info",
                message: data.statusMessage
              });
              this.$router.push({
                path: "/login"
              });
            }
          })
          .catch(msg => {
            self.$message({
              type: "info",
              message: "服务器异常"
            });
          });
      }
    },
    // 路由跳转
    fetchPathFun(val) {
      var valPath = this.$route.path;
      console.log(valPath);
      if (
        valPath == "/home/business/statistics" ||
        valPath == "/home/business/statisticsActive" ||
        valPath == "/home/business/statisticsDimission"
      ) {
        this.isBarSelectLi = 0;
      } else if (valPath == "/home/business/adminlist") {
        this.isBarSelectLi = 1;
      } else {
        this.isBarSelectLi = -1;
      }
    },
    // 点击侧栏
    barListsClick(index) {
      this.isBarSelectLi = index;
      this.isBarNoSelectLi = index;
      this.$router.push({
        path: "/home/business/" + this.barLists[index].path
      });
    },
    // 触摸侧栏
    barListsMouse(index) {
      if (this.isBarSelectLi == index) {
        this.isBarNoSelectLi = -1;
      } else {
        this.isBarNoSelectLi = index;
      }
    },
    ...mapActions([])
  }
};
</script>
<style scoped>
.homeData-left ul {
  display: flex;
  flex-wrap: wrap;
  width: 100%;
  margin-top: 15px;
}
.barNoSelectLi {
  background-color: #eeeeee;
}
.barSelectLi {
  background-color: #38adff;
  color: #fff;
}
.barLi {
  width: 100%;
  height: 40px;
  overflow: hidden;
  padding-left: 14px;
  font-size: 14px;
  line-height: 40px;
  cursor: pointer;
  user-select: none;
}
.homeData-left {
  width: 300px;
  background-color: #f4f6f8;
  box-sizing: content-box;
}

.homeData-right {
  width: 898px;
  min-height: 697px;
  background-color: #fff;
  border-left: 1px solid #dedede;
}

.businessdata {
  overflow: hidden;
  width: 100%;
  background-color: #fff;
  min-height: 100%;
  display: flex;
  justify-content: space-between;
  border-radius: 5px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05);
}
</style>